import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provide/provide.dart';
import '../../provide/details_info_provide.dart';
import '../../provide/cart_provide.dart';
import '../../provide/current_index.dart';



class DetailsFotter extends StatelessWidget {
  const DetailsFotter({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var goodInfo = Provide.value<DetailsProviedInfo>(context).goodsInfo.data.goodInfo;
    print('>>>>>$goodInfo');
    return Container(
      width: ScreenUtil().setWidth(750),
      height: ScreenUtil().setHeight(100),
      color: Colors.white,
      child: Row(
        children: <Widget>[
          Stack(
            children: <Widget>[
            InkWell(
              onTap: (){
                Provide.value<CurrentIndexProvide>(context).changeIndex(2);
                Navigator.pop(context);
              },
              child: Container(
                width: ScreenUtil().setWidth(110),
                height: ScreenUtil().setHeight(100),
                alignment: Alignment.center,
                child: Icon(
                  Icons.shopping_cart,
                  size:35.0,
                  color: Colors.red,
                ),
              ),
            ),
            Provide<CartProvide>(
                builder: (context,child,val){
                  int goodsCount = Provide.value<CartProvide>(context).allGoodsCount;
                  print('>>>$goodsCount');
                  return Positioned(
                    top: 0,
                    right: 4,
                    
                    child:Container(
                      padding: EdgeInsets.fromLTRB(6,3,6,3),
                      width: ScreenUtil().setWidth(40.0),
                      height: ScreenUtil().setHeight(40.0),
                      decoration: BoxDecoration (
                        color: Colors.pink,
                        border:Border.all(width: 0.5,color: Colors.white),
                        borderRadius: BorderRadius.circular(12.0)
                      ),
                      child: Text(
                        '$goodsCount',
                        style: TextStyle(
                          fontSize: ScreenUtil().setSp(12.0)
                        ),
                      ),
                    ),
                  );
                },
              )
            ],
          ),
          InkWell(
            onTap: (){
              Provide.value<CartProvide>(context).save(
                goodInfo.goodsId,
                goodInfo.goodsName,
                1,
                goodInfo.presentPrice,
                goodInfo.image1
              );
            },  
            child: Container(
              width: ScreenUtil().setWidth(320.0),
              height: ScreenUtil().setHeight(100),
              color: Colors.green,
              alignment: Alignment.center,
              child: Text(
                '加入购物车',
                style: TextStyle(
                  color: Colors.white,
                  fontSize: ScreenUtil().setSp(28.0),
                ),
              )
            ),
          ),
          InkWell(
            onTap: (){
              Provide.value<CartProvide>(context).remove();
            },
            child: Container(
              width: ScreenUtil().setWidth(320.0),
              height: ScreenUtil().setHeight(100),
              color: Colors.red,
              alignment: Alignment.center,
              child: Text(
                '立即购买',
                style: TextStyle(
                  color: Colors.white,
                  fontSize: ScreenUtil().setSp(28.0),
                ),
              )
            ),
          ),
        ],
      ),
    );
  }
}